package service;

import java.math.BigInteger;
import java.util.List;

import beans.Agent;
import beans.Branch;

import dao.BranchDao;
import dao.QueryDAO;


public class BranchService implements BranchServiceInterface {

    private List<Branch> branchs = null;

    QueryDAO queryDAO = new QueryDAO();
    BranchDao branchDao = new BranchDao();

    String sql = null;
    String hql = null;

    public List<Branch> getBranches(Agent agent, int rows, int page) {
        return branchDao.getBranches(agent, rows, page);
    }

    public int getBranchNumber(Agent agent) {
        sql = "select count(b.branch_id) from branch b where b.branch_agent_id = ?";
        return ((BigInteger)queryDAO.queryUniques(sql, agent.getId())).intValue();
    }

    public void deleteBranch(String ids) {//delete 操作不能用表别名
        sql = "delete from branch where branch_id in ("+ids+")";
        queryDAO.queryExcute(sql);
        sql = "delete from branch_sms_template where branch_id in ("+ids+")";
        queryDAO.queryExcute(sql);
    }

}